CreateWorkspace Method Example

This example uses the CreateWorkspace method to create both a Microsoft Jet workspace and an ODBCDirect workspace. It then lists the properties of both types of workspace.

Sub CreateWorkspaceX()

   Dim wrkODBC As Workspace
   Dim wrkJet As Workspace
   Dim wrkLoop As Workspace
   Dim prpLoop As Property

   ' Create an ODBCDirect workspace. Until you create 
   ' Microsoft Jet workspace, the Microsoft Jet database 
   ' engine will not be loaded into memory.
   Set wrkODBC = CreateWorkspace("ODBCWorkspace", "admin", _
      "", dbUseODBC)
   Workspaces.Append wrkODBC

   DefaultType = dbUseJet
   ' Create an unnamed Workspace object of the type 
   ' specified by the DefaultType property of DBEngine 
   ' (dbUseJet).
   Set wrkJet = CreateWorkspace("", "admin", "")

   ' Enumerate Workspaces collection.
   Debug.Print "Workspace objects in Workspaces collection:"
   For Each wrkLoop In Workspaces
      Debug.Print "  " & wrkLoop.Name
   Next wrkLoop

   With wrkODBC
      ' Enumerate Properties collection of ODBCDirect 
      ' workspace.
      Debug.Print "Properties of " & .Name
      On Error Resume Next
      For Each prpLoop In .Properties
         Debug.Print "  " & prpLoop.Name & " = " & prpLoop
      Next prpLoop
      On Error GoTo 0
   End With

   With wrkJet
      ' Enumerate Properties collection of Microsoft Jet 
      ' workspace.
      Debug.Print _
         "Properties of unnamed Microsoft Jet workspace"
      On Error Resume Next
      For Each prpLoop In .Properties
         Debug.Print "  " & prpLoop.Name & " = " & prpLoop
      Next prpLoop
      On Error GoTo 0
   End With

   wrkODBC.Close
   wrkJet.Close

End Sub